<?php

require_once 'Basic.php';

abstract class FormFieldType {
  
  protected $htmlClass;
  protected $htmlId;
  protected $inputSize;
  
  public function setId($htmlId) {
    $this->htmlId = $htmlId;
  }
  
  public function addHtmlClass($htmlClass) {
    $this->htmlClass .= " ${htmlClass}";
  }
  
  public function setInputSize($inputSize) {
    $this->inputSize = $inputSize;
  }
  
  protected function commonAttributes() {
    $out = "class='" . $this->htmlClass . "' " . "size='" . $this->inputSize . "'";
    if($this->htmlId !== null) {
      $out .= " id='" . $this->htmlId . "'";
    }
    return $out;
  }
  
  protected function commonHtml($name, $value) {
    $out = "<input type='text' name='${name}' " . $this->commonAttributes();
    if($value !== null) {
      $out .= " value='${value}'";
    }
    $out .= ">";
    return $out;
  }
  
  public abstract function getHtml($name, $value);
  
  /**
   * Essa $input deve ser passado por um trim.
   */
  public abstract function validate($input);
  
  
  /**
   * Isso deve colocar a classe do html deste FormFieldType para o padrão.
   */
  public abstract function clearHtmlClass();
}
